// 定义公共Store数据接口函数
import request from "@/utils/request";
import {
    CommonData,
    getAllProjectNameListData,
    getRequirementTypesData,
    getRoleUser,
    getInitRequirementData,
    postPvPRequirementForm,
    postPvPRequirementData,
    putUploadRequriementForm,
    putUpdateGetTestForm,
} from "./type";

// 接口地址
enum Commons {
    GetItemList = "/item/getItemList",
    GetRequirementTypes = "/item/getRequirementTypes",
    GetRoleUsers = "/user/getRoleUser",
    GetInitRequirement = "/item/getInitRequirement",//获取我负责的需求
    PostNoPVPRequirements = "/item/getPvPRequirement",//获取研发任务
    PostUploadFile = "/file/upload_file", //上传文件
    PutUploadRequriementSummary = "/item/uploadRequirementSummary",//上传附件后调用的接口
    PutUpdateGetTest = "/item/updateRequirementIsGetTest",//判断是否需求测试，及对项目经理的评论
}

// 获取所有项目名称
export const getItemList = () => request.get<getAllProjectNameListData>(Commons.GetItemList);

// 获取所有需求类型
export const getReqTypesList = () => request.get<getRequirementTypesData>(Commons.GetRequirementTypes);

// 根据权限获取人员信息
export const getRoleUsers = (data: any) => request.get<CommonData<getRoleUser[]>>(`${Commons.GetRoleUsers}?authId=${data}`);

// 获取我负责的需求
export const getInitRequirement = () => request.get<getInitRequirementData>(Commons.GetInitRequirement);

// 获取研发任务
export const postPVPRequirments = (data: postPvPRequirementForm) => request.post<CommonData<postPvPRequirementData[]>>(Commons.PostNoPVPRequirements, data);

// 上传文件
export const postUploadFile = (file: any, fileType: string, fileTypeId: string ) => {
    const formData = new FormData();
    formData.append("file", file);
    formData.append("fileType", fileType);
    formData.append("fileTypeId", fileTypeId);
    return request.post(Commons.PostUploadFile, formData, {
        headers: {
        "Content-Type": "multipart/form-data",
        },
    });
};

// 上传附件后调用的接口
export const PutUploadRequriement = (data: putUploadRequriementForm) => request.put<CommonData<any>>(Commons.PutUploadRequriementSummary, data);

// 判断是否需求测试，及对项目经理的评论
export const PutUpdateGetTest = (data: putUpdateGetTestForm) => request.put<CommonData<any>>(Commons.PutUpdateGetTest, data);
